<include file='Common:header' />
<div class="main-container" id="main-container">
	<include file='Common:left' />
	<div class="main-content">
		<div class="main-content-inner">
			<div class="page-content">
				<div class="row maintop">
					<div style="margin:10px 0;" id="rule-add">
						<form class="form-horizontal" name="admin_rule_add" id="admin_rule_add" method="post" action="{:U('admin_rule_runadd')}">
							<div class="col-xs-12 col-sm-12">
								<small>状态：</small>
								<small>
									<select name="status">
										<option value="1">显示</option>
										<option value="0">不显示</option>
									</select>
								</small>
								<small class="sl-left10">父级：</small>
								<small>
									<select name="pid">
										<option value="0">--默认顶级--</option>
										<foreach name="admin_rule" item="v">
											<option value="{$v.id}" style="margin-left:55px;">{$v.lefthtml}{$v.title}</option>
										</foreach>
									</select>
								</small>
								<small class="sl-left10">名称：</small>
								<small><input name="title" id="title" class="rule"  placeholder=" 输入名称" /></small>
								<small class="sl-left10">控/方：</small>
								<small><input name="name" id="name" class="rule"  placeholder=" 输入控制器/方法" /></small>
								<small class="sl-left10">css：</small>
								<small><input name="css" id="css" class="wh50"  placeholder=" css样式" /></small>
								<small class="sl-left10">排序：</small>
								<small><input name="sort" id="sort" class="wh30" value="50"/></small>
								<small>
									<button class="btn btn-xs btn-danger ruleadd">
										添加权限
									</button>
								</small>
							</div>
						</form>
					</div>
					<div class="col-xs-12 col-sm-12 rule-top alert alert-info top40">
						<button type="button" class="close" data-dismiss="alert">
							<i class="ace-icon fa fa-times"></i>
						</button>
						1、《控/方》：意思是 控制器/方法; 例如 Sys/sys_list<br />
						2、菜单name检测规则：一级菜单=>控制器名，二级菜单=>不限制，但建议控制器/方法(选择默认的方法)，三级、四级菜单=>控制器/方法<br />
						3、css为控制左侧导航顶级栏目前图标样式(仅一级菜单有效)，具体可查看FontAwesome图标CSS样式
					</div>
					<div class="row">
						<div class="col-xs-12">
							<div>
								<form id="ruleorder" name="ruleorder" method="post" action="{:U('admin_rule_order')}" >
									<table class="table table-striped table-bordered table-hover" id="dynamic-table">
										<thead>
										<tr>
											<th>ID</th>
											<th class="hidden-xs">权限名称</th>
											<th>控制器/方法</th>
											<th>显示</th>
											<th class="hidden-sm hidden-xs">级别</th>
											<th class="hidden-sm hidden-xs">添加时间</th>
											<th class="hidden-sm hidden-xs">排序</th>
											<th>操作</th>
										</tr>
										</thead>
										<tbody>
										<foreach name="admin_rule" item="v">
											<tr>
												<td height="28">{$v.id}</td>
												<td class="hidden-xs" style='padding-left:<if condition="$v.leftpin neq 0">{$v.leftpin}px</if>' >{$v.lefthtml}{$v.title}</td>
												<td>{$v.name}</td>
												<td>
													<if condition='$v[status] eq 1'>
														<a class="red" href="javascript:;" onclick="return stateyes({$v.id});" title="显示">
															<div id="zt{$v.id}"><button class="btn btn-minier btn-yellow">显示</button></div>
														</a>
														<else/>
														<a class="red" href="javascript:;" onclick="return stateyes({$v.id});" title="隐藏">
															<div id="zt{$v.id}"><button class="btn btn-minier btn-danger">隐藏</button></div>
														</a>														</if>														</td>
												<td class="hidden-sm hidden-xs">{$v.level}级</td>
												<td class="hidden-sm hidden-xs">{$v.addtime|date='Y-m-d',###}</td>
												<td class="hidden-sm hidden-xs"><input name="{$v.id}" value=" {$v.sort}" class="list_order"/></td>
												<td>
													<div class="hidden-sm hidden-xs action-buttons">
														<a class="green" href="{:U('admin_rule_edit',array('id'=>$v['id']))}" title="修改">
															<i class="ace-icon fa fa-pencil bigger-130"></i>
														</a>
														<a class="green" href="{:U('admin_rule_copy',array('id'=>$v['id']))}" title="复制">
															<i class="ace-icon fa fa-exchange bigger-130"></i>
														</a>
														<a class="red del" href="{:U('admin_rule_del',array('id'=>$v['id']))}" title="删除">
															<i class="ace-icon fa fa-trash-o bigger-130"></i>							</a>							
													</div>
													<div class="hidden-md hidden-lg">
															<div class="inline position-relative">
																<button class="btn btn-minier btn-primary dropdown-toggle" data-toggle="dropdown" data-position="auto">
																	<i class="ace-icon fa fa-cog icon-only bigger-110"></i>
																</button>
																<ul class="dropdown-menu dropdown-only-icon dropdown-yellow dropdown-menu-right dropdown-caret dropdown-close">
																	<li>
																		<a href="{:U('admin_rule_edit',array('id'=>$v['id']))}" class="tooltip-success" data-rel="tooltip" title="" data-original-title="修改">
																			<span class="green">
																				<i class="ace-icon fa fa-pencil-square-o bigger-120"></i>
																			</span>
																		</a>
																	</li>
																	<li>
																		<a href="{:U('admin_rule_copy',array('id'=>$v['id']))}" class="tooltip-success" data-rel="tooltip" title="" data-original-title="复制">
																			<span class="green">
																				<i class="ace-icon fa fa-exchange bigger-120"></i>
																			</span>
																		</a>
																	</li>
																	<li>
																		<a href="{:U('admin_rule_del',array('id'=>$v['id']))}"  class="tooltip-error del" data-rel="tooltip" title="" data-original-title="删除">
																			<span class="red">
																				<i class="ace-icon fa fa-trash-o bigger-120"></i>
																			</span>
																		</a>
																	</li>
																</ul>
															</div>
													</div>
												</td>
											</tr>
										</foreach>
										<tr>
											<td colspan="8" align="left"><button type="submit"  id="btnorder" class="btn btn-white btn-yellow btn-sm">排序</button></td>
										</tr>
										</tbody>
									</table>
								</form>
							</div>
							<include file='Common:header_nav' />
							<script>
								//状态操作
								function stateyes(val){
									$.post('{:U("admin_rule_state")}',
											{x:val},
											function(data){
												if(data.status){
													if(data.info=='状态禁止'){
														var a='<button class="btn btn-minier btn-danger">隐藏</button>'
														$('#zt'+val).html(a);
														return false;
													}else{
														var b='<button class="btn btn-minier btn-yellow">显示</button>'
														$('#zt'+val).html(b);
														return false;
													}
												}else{
													layer.alert(data.info, {icon: 5});
												}
											});
									return false;
								}
							</script>
							<script>
								$(function(){
									//删除操作
									var $del = $(".del");
									$del.click(function(){
										var $url=this.href;
										layer.confirm('你确定要删除吗？', {icon: 3}, function(index){
										layer.close(index);
										$.get($url, function(data){
											if(data.status){
												layer.alert(data.info, {icon: 6}, function(index){
													layer.close(index);
													window.location.href=data.url;
												});
											} else {
												layer.alert(data.info, {icon: 5}, function(index){
													layer.close(index);
													//window.location.href="{:U('we_menu_list')}";
												});
											}
										}, "json");
										});
										return false;
									});
									//添加操作
									$('#admin_rule_add').ajaxForm({
										beforeSubmit: checkForm, // 此方法主要是提交前执行的方法，根据需要设置
										success: complete, // 这是提交后的方法
										dataType: 'json'
									});

									function checkForm(){
										if( '' == $.trim($('#title').val())){
											layer.alert('名称不能为空', {icon: 5}, function(index){
												layer.close(index);
												$('#title').focus();
											});
											return false;
										}
										if( '' == $.trim($('#name').val())){
											layer.alert('控制器/方法不能为空', {icon: 5}, function(index){
												layer.close(index);
												$('#name').focus();
											});
											return false;
										}
									}
									function complete(data){
										if(data.status==1){
											layer.alert(data.info, {icon: 6}, function(index){
												layer.close(index);
												window.location.href=data.url;
											});
										}else{
											layer.alert(data.info, {icon: 5}, function(index){
												layer.close(index);
												//window.location.href="{:U('admin_rule_list')}";
											});
											return false;
										}
									}
								});
								//排序操作
								$(function(){
									$('#ruleorder').ajaxForm({
										success: complete, // 这是提交后的方法
										dataType: 'json'
									});
									function complete(data){
										if(data.status==1){
											layer.alert(data.info, {icon: 6}, function(index){
												layer.close(index);
												window.location.href=data.url;
											});
										}else{
											layer.alert(data.info, {icon: 5});
										}
									}
								});
								//固定添加rule的表单，方便添加
								$(function(){
									$('#rule-add').insertAfter($('#header-nav'));
								});
							</script>
						</div><!-- /.page-content -->
					</div>
				</div><!-- /.main-content -->
				<include file='Common:footer' />
			</div><!-- /.main-container -->
			</body>
			</html>